package com.example.win.android_banduyujia.peopleactivity.activity.activity.openactivity;

import android.app.NotificationManager;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.example.win.android_banduyujia.R;
import com.example.win.android_banduyujia.peopleactivity.adapter.NotificationAdapter;
import com.example.win.android_banduyujia.peopleactivity.ui.activity.BaseTitleBarActivity;
import com.example.win.android_banduyujia.peopleactivity.ui.layout.RefreshLayout;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by Win on 2015/8/21.
 */
public class NotificationActivity extends BaseTitleBarActivity implements SwipeRefreshLayout.OnRefreshListener, RefreshLayout.OnLoadListener {

    private static final String  MY_ACTION = "com.android.notification.MY_ACTION";
    private static final int NOTIGICATION_ID_1 = 0;

    private ImageView mImageView;
    private static int messageNum = 0;
    //private Context  context = this;
    private NotificationManager  manager;
    private Bitmap   icon;

    private RefreshLayout   swipeLayout;
    private ArrayList<HashMap<String, String>>  list;
    private View header;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_notifica_tion_book);

        InitTitles();
        InitViews();
        InitVerictor();
        setListener();
    }

    private void InitTitles() {
        showLeftBackButton();
        setTitle(R.string.layout_notification_text);
    }

    private void InitViews() {
        /*// 获取通知服务
        manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        icon = BitmapFactory.decodeResource(getResources(), R.mipmap.icon);

        mImageView = (ImageView)findViewById(R.id.layout_notification_image_view);
        mImageView.setOnClickListener(this);*/

        header = getLayoutInflater().inflate(R.layout.layout_refresh_header, null);
        swipeLayout= (RefreshLayout) findViewById(R.id.swipe_container);
        swipeLayout.setOnRefreshListener(this);
        swipeLayout.setColorScheme(android.R.color.holo_blue_bright,
                android.R.color.holo_green_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);

        list = new ArrayList<HashMap<String,String>>();
        for(int i=0; i <10;i++){
            list.add(new HashMap<String, String>());
        }
    }

    private void InitVerictor() {
        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.revyvler_notification_list_vertical);
        LinearLayoutManager  layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);

        String[]  dabaset = new String[2];
        for(int i=0;i> dabaset.length;i++){
            dabaset[2]="items"+i;
        }
        NotificationAdapter adapter = new NotificationAdapter(dabaset);
        recyclerView.setAdapter(adapter);

        /*MyNotification notification = new MyNotification();
        notification.execute(0);

        mDialog = new ProgressDialog(this);
        mDialog.setMessage("请稍后.......");*/
    }

    private void setListener() {
        swipeLayout.setOnRefreshListener(this);
        swipeLayout.setOnLoadListener(this);
    }

    @Override
    public void onRefresh() {
         swipeLayout.postDelayed(new Runnable() {
             @Override
             public void run() {
                // 更新数据
                 // 更新量调用该方法结束刷新
                 swipeLayout.setRefreshing(false);
             }
         },1000);
    }

    @Override
    public void onLoad() {
        swipeLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                // 更新数据
                // 更新完后调用该方法结束刷新
                swipeLayout.setLoading(false);
            }
        },1000);
    }

     /*@Override
    public void onClick(View v) {
       switch (v.getId()){
            case R.id.layout_notification_image_view:
                 notificationActivity();
                break;
        }
    }*/

    /* private void notificationActivity() {
        NotificationCompat.BigPictureStyle  pictureStyle = new NotificationCompat.BigPictureStyle();
        pictureStyle.setBigContentTitle("般度瑜伽")
                .setSummaryText("般度")
                .bigLargeIcon(icon);
        Notification  notification = new NotificationCompat.Builder(context)
                                         .setLargeIcon(icon).setSmallIcon(R.mipmap.icon)
                                         .setTicker("show time").setContentInfo("瑜伽")
                                         .setContentTitle("般度瑜伽").setContentText("般度")
                                         .setStyle(pictureStyle)
                                         .setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL)
                                         .build();
        manager.notify(NOTIGICATION_ID_1, notification);
    }*/

    /*class MyNotification extends AsyncTask<Integer, Integer, Integer>{

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            mDialog.show();
        }

        @Override
        protected Integer doInBackground(Integer... params) {
            int  number = params[0];
            for(int i=0;i<10;i++){
                number++;

                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            return number;
        }

        @Override
        protected void onPostExecute(Integer result) {
            super.onPostExecute(result);
            mDialog.cancel();

            Toast.makeText(NotificationActivity.this, "Task:"+result, Toast.LENGTH_SHORT).show();
        }
    }*/
}
